package net.demo;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/*@Configuration 让Spring来加载该类配置 */
/*@EnableSwagger2 注解来启用Swagger2*/
@Configuration
@EnableSwagger2
public class Swagger2 {
	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
				.apis(RequestHandlerSelectors
						.basePackage("net.demo.api")) /*
																 * Swagger会扫描该包下所有Controller定义的API
																 * ，并产生文档内容（
																 * 除了被@ApiIgnore指定的请求）
																 */
				.paths(PathSelectors.any()).build();
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title("TaskManager定时任务管理").description("restful API")
				.termsOfServiceUrl("http:localhost").contact("CJB").version("1.0").build();
	}
}